﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using Osiptel.HECO.BE;
using System.Data.OracleClient;
using System.Data;

namespace Osiptel.HECO.DL
{
    public class Predefinido2DL
    {
        
        public int mInsertar(Predefinido2BE Predefinido2)
        {
            
            try
            {
                Int32 id = 0;

                using (OracleCommand cmd = new OracleCommand())
                {
                    cmd.CommandText = "PKG_HECO_GLOBAL.SP_INSERTAR_PREDEFINIDO2";
                    cmd.CommandType = CommandType.StoredProcedure;

                    OracleParameter prm1 = new OracleParameter("PLONGITUDENLACE", OracleType.Number);
                    OracleParameter prm2 = new OracleParameter("PLONGITUDCARRETE", OracleType.Number);
                    OracleParameter prm3 = new OracleParameter("PNUMEROHILOS", OracleType.Number);
                    OracleParameter prm4 = new OracleParameter("PP07TIPOINSTALACION", OracleType.Number);
                    OracleParameter prm5 = new OracleParameter("PCOSTOKM", OracleType.Number);
                    OracleParameter prm6 = new OracleParameter("PCANTIDADTORRES", OracleType.Number);
                    OracleParameter prm7 = new OracleParameter("PUSUCRE", OracleType.VarChar);
                    OracleParameter prm8 = new OracleParameter("PIPREG", OracleType.VarChar);
                    OracleParameter prm9 = new OracleParameter("PIDPREDEF2", OracleType.Number);

                    prm1.Direction = ParameterDirection.Input;
                    prm2.Direction = ParameterDirection.Input;
                    prm3.Direction = ParameterDirection.Input;
                    prm4.Direction = ParameterDirection.Input;
                    prm5.Direction = ParameterDirection.Input;
                    prm6.Direction = ParameterDirection.Input;
                    prm7.Direction = ParameterDirection.Input;
                    prm8.Direction = ParameterDirection.Input;
                    prm9.Direction = ParameterDirection.Output;

                    prm1.Value = Predefinido2.LongitudEnlace;
                    prm2.Value = Predefinido2.LongitudCarrete;
                    prm3.Value = Predefinido2.NumeroHilos;
                    prm4.Value = Predefinido2.P07TipoInstalacion;
                    prm5.Value = Predefinido2.Costokm;
                    prm6.Value = Predefinido2.CantidadTorres;  
                    prm7.Value = Predefinido2.UsuCre;
                    prm8.Value = Predefinido2.IpReg;
                    prm9.Value = Predefinido2.IdPredefinido;

                    cmd.Parameters.Add(prm1);
                    cmd.Parameters.Add(prm2);
                    cmd.Parameters.Add(prm3);
                    cmd.Parameters.Add(prm4);
                    cmd.Parameters.Add(prm5);
                    cmd.Parameters.Add(prm6);
                    cmd.Parameters.Add(prm7);
                    cmd.Parameters.Add(prm8);
                    cmd.Parameters.Add(prm9);

                    using (DL_CONEXION NewConexion = new DL_CONEXION())
                    {
                        int ret = NewConexion.ejecutaSQL(cmd);
                        id = Convert.ToInt32(Convert.ToString(cmd.Parameters["PIDPREDEF2"].Value));
                        return id;
                    }                    
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }       
    }
}
